/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tweetbotserver.robot.comms.encoder.encoders;

import tweetbotserver.robot.comms.BotMessage;
import tweetbotserver.robot.comms.encoder.BotMessageEncoder;

/**
 *
 * @author Mike
 */
public class StringBotMessageEncoder implements BotMessageEncoder<String> {

    @Override
    public byte[] encode(BotMessage<String> input) {
        byte[] result = null;
        try {
            result = input.getContent().getBytes("UTF8");//in byte array
        } catch (Exception e) {
            System.out.println("Error encoding string! - " + e.toString());
        }

        return result;
    }

    @Override
    public BotMessage<String> decode(byte[] bytes) {
        BotMessage result = null;
        try {
            String stringData = new String(bytes, 0, bytes.length, "UTF8");//in string
            result = new BotMessage(stringData);

        } catch (Exception e) {
            System.out.println("Error decoding bytes to string! - " + e.toString());
        }
        return result;
    }
}
